<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){	
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$orderby='id desc';
	$type=intval($_RQ['type']);
	$params['type']=$type;	
	if(isset($_RQ['status'])){
		if($_RQ['status']=='other'){
			$orderby='daytime asc';
			$status='0';
		}else{
			$status=$_RQ['status'];
		}
		$params['status']=$status;
		$return['params']['status']=$status;
	}
	if($_RQ['mid']){
		$params['mid']=$_RQ['mid'];
		$return['params']['mid']=$_RQ['mid'];
	}
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_wxshifu_sendlog',$params,array($pindex,$psize),$total,'','',$orderby);
	$work_weekarray=array('日','一','二','三','四','五','六');
	if($list){
		foreach($list as &$item){
			$order=$this->get('order',array('id'=>intval($item['order_id']),'uniacid'=>$_SESSION['uniacid']));
			$order=$this->model('model')->getorder($order);
			$item['ordersn']=$order['ordersn'];
			$item['buymid']=$order['mid'];
			$week = date('w', strtotime($item['day']));
			$item['week'] = '星期'.$work_weekarray[$week];
			$item['dayweek'] = $item['day'].$item['week'];
			$item['address']=$order['addresstext'];
			if($item['shifuid']){
				$item['peimember']=pdo_get('jy_wxshifu_member',array('id'=>$item['shifuid'],'uniacid'=>$_SESSION['uniacid']),array('title','mobile'));
				$item['peimember']['nickname']=$item['peimember']['title'];
			}
			$item['member']=cfc('core')->member_show($order['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'客户','type'=>'member'),
			//array('name'=>'dayweek','title'=>'日期','type'=>'string'),
			array('name'=>'peimember','title'=>$this->shifutitle,'type'=>'member'),
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'address','title'=>'地址','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'send_status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','op'=>'look','title'=>'查看详情'),
		)),
		'search'=>array(
			array('name'=>'status','width'=>10,'title'=>'状态','type'=>'radio','options'=>'send_status'),
			array('type'=>'select','width'=>10,'name'=>'shifuid','options'=>'shifus','title'=>'选择'.$this->shifutitle),
			array('name'=>'createtime','width'=>15,'title'=>'下单时间','type'=>'time_range')
		),
	);
	$return['htmls']=$htmls;
	$return['shifus']=pdo_getall('jy_wxshifu_member',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['send_status']=$this->sendlog_status;
	$return['send_types']=$this->send_types;
	exi($return);
}
if($_RQ['op']=='look'){
	$item=$this->get('sendlog',array('id'=>intval($_RQ['id']),'uniacid'=>$_SESSION['uniacid']));
	if(!$item){
		exi('指定单不存在！','error');
	}
	$work_weekarray=array('日','一','二','三','四','五','六');
	$item['goods']=json_decode($item['goods'],true);
	$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
	$item['is_addtitle']=$item['is_add']?'获得':'消费';
	$item['ordersn']=pdo_getcolumn('jy_weishop_order',array('id'=>$item['order_id']),'ordersn');
	$week = date('w', strtotime($item['day']));
	$item['week'] = '星期'.$work_weekarray[$week];
	$item['dayweek'] = $item['day'].$item['week'];
	$order=$this->model('model')->getorder($item);
	//用户地址
	$order['address']=json_decode($order['address'],true);
	if($order['address'] && ($order['address']['name'] || $order['address']['realname'])){
				$address=$order['address'];
	}else{
				$address=pdo_get('core_address',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['addressid']));
	}
	if(!is_array($address['pcd'])){
				$address['pcd']=json_decode($address['pcd'],true);
	}
	$item['order_out']=$address;
	if($item['mid']){
				$item['peimember']=pdo_get('jy_wxshifu_member',array('mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('title','mobile'));
				$item['peimember']['nickname']=$item['peimember']['title'];
	}
	$item['get_money']=$this->model('model')->get_peifee($order,$item['mid'],$item['goods']);
	$item['order']=$order;
	$item['member']=cfc('core')->member_show($order['mid']);
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'服务单详情',
		'look'=>array(
			array('name'=>'buymid','title'=>'客户ID','type'=>'string'),
			array('name'=>'member','title'=>'客户','type'=>'member'),
			array('name'=>'dayweek','title'=>'日期','type'=>'string'),
			array('name'=>'peimember','title'=>$this->shifutitle,'type'=>'member'),
			array('name'=>'order.price','title'=>'订单金额','type'=>'string'),
			//array('name'=>'get_money','title'=>'服务费','type'=>'string'),
			array('name'=>'order_out.pcd','title'=>'地址','type'=>'pcd'),
			array('name'=>'order_out.address','title'=>'详细地址','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'send_status'),
		),
	);
	$return['send_status']=$this->sendlog_status;
	$return['send_types']=$this->send_types;
	exi($return);
}

if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_wxshifu_sendlog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}